import { defineStore } from 'pinia'
import { defaultLayout } from '@/settings.ts'

interface AppInfoState {
  title: string
  logo: string
  description: string
  version: string
}

interface AppState {
  collapsed: boolean
  isDark: boolean
  layout: string
  info: AppInfoState
}

export const useAppStore = defineStore('app', {
  state: (): AppState => ({
    collapsed: false,
    isDark: false,
    layout: defaultLayout,
    info: {
      logo: '',
      title: import.meta.env['VITE_TITLE'],
      description: '',
      version: '',
    },
  }),
  actions: {
    switchCollapsed() {
      this.collapsed = !this.collapsed
    },
    setCollapsed(b: boolean) {
      this.collapsed = b
    },
    setLayout(layout: string) {
      this.layout = layout
    },
  },
  persist: {
    paths: ['collapsed'],
    storage: sessionStorage,
  },
})
